<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/easyui/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/easyui/themes/icon.css">
<script type="text/javascript" src="${pageContext.request.contextPath}/static/easyui/jquery.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/static/easyui/jquery.easyui.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/static/easyui/locale/easyui-lang-zh_CN.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>流程部署管理</title>
</head>
<body>
<table id="processDeployTable" fit="true"></table>
<div id="tb">
	<a class="easyui-linkbutton" iconCls="icon-add" onclick="addProcess()" plain="true">新增</a>
	<a class="easyui-linkbutton" iconCls="icon-remove" onclick="removeProcess()" plain="true">删除</a>
</div>

<div id="addProcessDialog">
	<form id="addProcessForm"  enctype="multipart/form-data" method="post">
		<table align="center" cellspacing="5px"  cellpadding="6px" style="margin-top: 15px;">
			<tr >
				<td >上传流程: </td>
				<td>
					<input type="file" id="file" name="file" >
					<span style="color: red">*</span>
				</td>
			</tr>
		</table>
	</form>
</div>
<div id="tt">
	<a class="easyui-linkbutton" iconCls="icon-save" plain="true" onclick="save()">上传</a>
	<a class="easyui-linkbutton" iconCls="icon-cancel" plain="true" onclick="cancel()">取消</a>
</div>


</body>
<script type="text/javascript">
$(function(){
	$("#processDeployTable").datagrid({
		url:"${pageContext.request.contextPath}/getAllProcessByPage",
		title:"流程部署管理",
		toolbar:"#tb",
		fitColumns:true,
		rownumbers:true,
		pagination:true,
		//singleSelect:true,
		columns:[[
			{field:'ck',checkbox:"true"},
			{field:"id",title:"编号",width:1,align:"center"},
			{field:"name",title:"流程名称",width:3,align:"center"},
			{field:"time",title:"流程部署时间",width:3,align:"center"}
		]]
	})
	
	$("#addProcessDialog").dialog({
		width:400,
		height:150,
		buttons:"#tt",
		title:"上传流程部署",
		closed:true
	})
	
})

function addProcess(){
	$("#addProcessForm").form("clear");
	$("#addProcessDialog").dialog("open");
	
}

	function removeProcess(){
		var data = $("#processDeployTable").datagrid("getSelections");
		if(data.length>0){
			$.messager.confirm("温馨提示","是否删除?",function(r){
				if(r){
					var arrId = [];
					for(var i in data){
						arrId.push(data[i].id);
					}
					console.log(arrId)
					$.ajax({
						url:"${pageContext.request.contextPath}/removeProcessByArrId",
						type:"post",
						async:true,
						traditional:true,
						data:{
							arrId:arrId
						},
						success:function(data){
							if(data=='success'){
								$.messager.alert("温馨提示","删除成功!","info",function(){
									$("#processDeployTable").datagrid("load");
								});
							}else{
								$.messager.alert("温馨提示","删除失败!","info");
							}
						}
					})
				}
			})
		}else{
			$.messager.alert("温馨提示","请选中要删除的数据","info");
		}
	
	}




function save(){
	var id = $("#file").val();
	if(!id){
		$.messager.alert("","请选择上传文件!","info");
		return false;
	}
	$("#addProcessForm").form("submit",{
		url:"${pageContext.request.contextPath}/uploadProcess",
		success:function(data){
			var i ;
			if(data=='success'){
				i = $.messager.alert("温馨提示","操作成功!","info",function(){
					$("#addProcessDialog").dialog("close");
					$("#processDeployTable").datagrid("load");
				});
				//2秒后自动关闭确认框
				setTimeout(function(){
					i.window("close");
					$("#addProcessDialog").dialog("close");
					$("#processDeployTable").datagrid("load");
				}, 2000);
			}else{
				i = $.messager.alert("温馨提示","操作失败!","info");
				setTimeout(function(){
					i.window("close");
				}, 2000);
			}
		}
	});
}
function cancel(){
	$("#addProcessDialog").dialog("close");
}











</script>
</html>